﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SysCommon
{
    public static class File
    {
        /// <summary>
        /// 读取文件返回二进制数据
        /// </summary>
        /// <param name="strFileName"></param>
        /// <returns></returns>
        public static  byte[] ReadFileBinary(string strFileName)
        {
            System.IO.FileStream fs = System.IO.File.OpenRead(strFileName);
            System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
            return  br.ReadBytes((int)fs.Length);
        }


        /// <summary> 
        /// 将Html标签转化为空 
        /// </summary> 
        /// <param name="strHtml">待转化的字符串</param> 
        /// <returns>经过转化的字符串</returns> 
        public static string GetStringNoHtml(string string_include_html)
        {
            if (String.IsNullOrEmpty(string_include_html))
            {
                return "";
            }
            else
            {
                string_include_html = string_include_html.Replace("<BR>", "\r\n").Replace("<br>", "\r\n");
                //第一种
                string string_no_html = System.Text.RegularExpressions.Regex.Replace(string_include_html, @"(<script[^>]*?>.*?</script>)|(<(.[^>]*)>)", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                return string_no_html.Replace("&nbsp;", " ");
                //第二种
                //return System.Text.RegularExpressions.Regex.Replace(string_include_html, @"(<script[^>]*?>.*?</script>)|(<(.[^>]*)>)|(&nbsp;)", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            }
        }
    }

    
}
